//delete//
const Utils = require('../util/utils');
const statusCode = require('../util/status-code')
const getPointPageList = require("../mock/server/getPointPageList");
const getPointList = require("../mock/server/getPointList");
const getPointDetail = require("../mock/server/getPointDetail");
const exportPoint = require("../mock/server/exportPoint");
const getAllPointList = require("../mock/server/getAllPointList");

//delete//
class BuryPointWarehouseController {
    /**
     * 创建信息
     * @param ctx
     * @returns {Promise.<void>}
     */
    static async create(ctx) {
        let req = JSON.parse(ctx.request.body);
        if (req.pointName && req.fields) {
            ctx.response.status = 200;
            ctx.body = statusCode.SUCCESS_200('创建点位仓库成功', '')
        } else {
            ctx.response.status = 412;
            ctx.body = statusCode.ERROR_412('创建点位仓库失败，请求参数不能为空！')
        }
    }

    /**
     * 更新
     * @param ctx
     * @returns {Promise.<void>}
     */
    static async update(ctx) {
        let req = JSON.parse(ctx.request.body);
        let id = req.id;
        if (req) {
            ctx.response.status = 200;
            ctx.body = statusCode.SUCCESS_200('更新信息成功！', '');
        } else {
            ctx.response.status = 412;
            ctx.body = statusCode.ERROR_412('更新信息失败！')
        }
    }

     /**
     * 查询单条信息数据
     * @param ctx
     * @returns {Promise.<void>}
     */
    static async detail(ctx) {
        const param = Utils.parseQs(ctx.request.url)
        let id = param.id;
        if (id) {
            ctx.response.status = 200;
            ctx.body = statusCode.SUCCESS_200('查询成功！', getPointDetail)
        } else {
            ctx.response.status = 412;
            ctx.body = statusCode.ERROR_412('信息ID必须传');
        }
    }


    static async delete(ctx) {
        let param = JSON.parse(ctx.request.body);
        const { id } = param
        // 删除前，先检查是否sdk发布还有该点位仓库 
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', "")
        
    }

    /**
     * page
     * @param 
     * 
     */
    static async getPageList(ctx) {
        let req = ctx.request.body
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', getPointPageList)
    }

    static async getList(ctx) {
        let req = ctx.request.body
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', getPointList)
    }

    static async getAllList(ctx) {
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', getPointList)
    }

    static async exportPoint(ctx) {
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', exportPoint)
    
    }

    static async getAllPointList(ctx) {
        ctx.response.status = 200;
        ctx.body = statusCode.SUCCESS_200('success', getAllPointList)

    }
}
//exports//
module.exports = BuryPointWarehouseController
//exports//